﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using VeMayBayDTO;

namespace VeMayBayDAO
{
    public class ChuyenBayDAO
    {
        public static List<ChuyenBayDTO> GetChuyenbayAll()
        {
            List<ChuyenBayDTO> list = new List<ChuyenBayDTO>();
            return list;
        }
        public static ChuyenBayDTO GetChuyenbayById(int id)
        {
            ChuyenBayDTO cb = new ChuyenBayDTO();
            return cb;
        }
        // lay chuyen bay moi insert vao
        public static ChuyenBayDTO GetLastChuyenBay()
        {
            ChuyenBayDTO cb = new ChuyenBayDTO();
           //
            cb.MayBay = new MayBayDTO();
            cb.HanhTrinh = new HanhTrinhDTO();
            //
            string query = "select * from lichchuyenbay order by machuyenbay desc";
            DataTable dt = new DataTable();
            dt = DataProvider.ExecQuery(query);
            if (dt.Rows.Count > 0)
            {
                cb.MaChuyenBay = (int)dt.Rows[0]["machuyenbay"];
                cb.TenChuyenBay = dt.Rows[0]["tenmachuyenbay"].ToString();
                cb.MayBay.MaMayBay = (int)dt.Rows[0]["mamaybay"];
                cb.HanhTrinh.MaHanhTrinh = (int)dt.Rows[0]["mahanhtrinh"];
                cb.NgayGio = Convert.ToDateTime(dt.Rows[0]["ngaygio"]);
                cb.ThoiGianBay = (int)dt.Rows[0]["thoigianbay"];
            }
            return cb;
        }

        public static bool NhanLich(ChuyenBayDTO cb)
        {
          
            string query = @"insert into lichchuyenbay (tenmachuyenbay,mamaybay,mahanhtrinh,ngaygio,thoigianbay) values 
                            ('" + cb.TenChuyenBay + "'," + cb.MayBay.MaMayBay + "," + cb.HanhTrinh.MaHanhTrinh + ",'" + cb.NgayGio.ToString() + "'," + cb.ThoiGianBay + ")";
            int n =(int) DataProvider.ExecNonQuery(query);
            if (n == 0)
                return false;
            return true;
        }
        public static bool CapNhat(ChuyenBayDTO sb)
        {
            return true;
        }
        public static bool HuyLich(string id)
        {
            return true;
        }
        public static int SoGheTrong(string chuyenbayID)
        {

            return 1;
        }
    }
}
